<template>
	<view class="classify-body">
		<view class="classify-left">
			<view class="nav-item" v-for="(item,index) in navList" :key="index" :class="{'active':current==index}" @click="navChange(item.id,index)">{{item.name}}</view>
		</view>
		<view class="classify-right">
			<view class="title-icon" v-if="parentClassify&&parentClassify.img_url">
				<image mode="widthFix" :src="parentClassify.img_url"></image>
			</view>
			<view class="card-section">
				<!-- <view class="title">
					<view class="title-left">
						<h1>中药材</h1>
						<image mode="widthFix" style="width: 80px;" src="../../static/goodClassify/title_bottom.png"></image>
					</view>
					<view>更多</view>
				</view> -->
				<view class="classify-list">
					<view class="classify-item"  v-for="(item,index) in nextClassifies" :key="index" @click="toGoodList(item.id,item.name)">
						<image mode="aspectFill" style="width: 57px;height: 57px;" :src="item.img_url"></image>
						<text>{{item.name}}</text>
					</view>
				</view>
			</view>

		</view>

		<!-- <u-row>
			<u-col span="3">
				<scroll-view scroll-y="true" style="height: 100vh;" show-scrollbar="false">
					<view class="classify-left" v-for="(sort,index) in medicineSort" :key="index" @click="clickSortName(sort,index)">
						<view class="left-nav-name"  :class="{'active':current==index}" >
							{{sort.name}}
						</view>
					</view>
				</scroll-view>
			</u-col>
			<u-col span="8" >
				<scroll-view scroll-y="true" style="height: 100vh;">
					<view class="classify-right">
						<view  style="display: flex;flex-wrap:wrap;">
							<view v-for="(item,index) in medicineSortAll[0].detail" :key="index" style="flex: 1;display: flex;flex-direction: column;align-items: center;">
								<image style="width: 130rpx;height: 124rpx;" :src="item.pic"></image>
								<view style="width: 130rpx;font-size: 28rpx; color: #999999;text-align: center;">{{item.detailName}}</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</u-col>
		</u-row> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				navList: [],//左边导航栏列表
				parentClassify: '',//选中的父分类
				nextClassifies: [],//父分类的子分类列表
				tempMerchantId: '',//判断店铺是否更新的标志
			}
		},
		onShow() {
			let merchant = wx.getStorageSync("merchant")
			if(merchant.merchant_id!=this.tempMerchantId||this.navList.length==0){
				this.getBuyingClassifyList();
			}
		},
		onLoad(){
			this.getBuyingClassifyList();
		},
		methods: {
			//获取销售药品用的分类
			async getBuyingClassifyList() {
				let merchant = wx.getStorageSync("merchant");
				if(merchant){
					this.tempMerchantId = merchant.merchant_id
					let res = await this.$api.getBuyingClassifyList({
						merchant_id: merchant.merchant_id
					},this.$baseUrl);
					if(res.data.level=="success"){
						this.navList = res.data.data;
						if(this.navList.length>0){
							this.parentClassify = this.navList[0]
							this.nextClassifies = this.navList[0].next_classifies
						} else{
							this.nextClassifies = []
							this.current = 0
							this.parentClassify = ''
						}
					} else{
						wx.showToast({
							icon: 'none',
							title: res.data.message
						})
					}
				} else {
					wx.showToast({
						icon: 'none',
						title: '请选择店铺'
					})
				}
			},
			navChange(id,index) {
				this.current = index
				this.parentClassify = this.navList[index]
				this.nextClassifies = this.navList[index].next_classifies
			},

			//跳转商品列表页面
			toGoodList(id,name){
				uni.navigateTo({
					url: '../goodsList/goodListByClassify?classifyId='+id+'&index='+id+'&name='+name
				})
			},

		}
	}
</script>

<style scoped lang="scss">
	@import "../../common/css/mixin.scss";
	.classify-body{
	    width: 100vw;
		max-height: 100vh;
		font-size: 14px;
	    @include flex(flex-start,flex-start);
	    flex-direction: row;
	    .classify-left{
	      width: 25vw;
	      color: #737277;
		  background-color: #f7f6fb;
		  height: 100vh;
		  overflow: auto;
	      .nav-item{
	        text-align: center;
	        height: 120rpx;
	        line-height: 120rpx;
	        margin-left: 3px;
			@include ellipsis(1)
	      }
	      .active{
			color: #000000;
			font-weight: bold;
	        border-left: 5px solid #1EDB9B;
	        margin-left: 0px;
			background-color: #FFFFFF;
	      }
	    }
	    .classify-right{
	      width: 75vw;
	      background: #ffffff;
		  max-height: 100vh;
		  overflow: auto;
		  .title-icon{
			  padding: 20px 20px 0;
			  display: flex;
			  justify-content: center;
			  image{
				  width: 100%;
				  height: auto;
				  border-radius: 10px;
			  }
		  }
		  .card-section{
			width: calc(100% - 40px);
			padding: 10px 20px;
			.title{
				display: flex;
				align-items: center;
				justify-content: space-between;
				/* padding: 0 5px; */
				.title-left{
					font-size: 16px;
					font-weight: bold;
					display: flex;
					flex-direction: column;
					text-align: center;
				}
			}
			.classify-list{
				padding-top: 25px;
				display: flex;
				flex-wrap: wrap;
				.classify-item{
					width: calc(100%/3);
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					margin-bottom: 20px;
					text{
						margin-top: 8px;
						@include ellipsis(1)
					}
				}
			}
		  }
	    }
	}
	/* .classify-body{
		text-align: center;

		.classify-left{
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			padding: 0rpx 20rpx 20rpx 0;
			color: #808080;
			margin-left: -10rpx;
			margin-top: 20rpx;
		}
		.classify-right{
			margin-top: 20rpx;
		}
	}
	.left-nav-name{
		font-size: 14px;
		color: #9F9F9F;
	}
	.active{
		border-left: 18rpx solid #4CD964;
		color: black;
		font-weight: bold;
	} */
	/* 隐藏滚动条 */
	/deep/.uni-scroll-view ::-webkit-scrollbar {
	 /* 隐藏滚动条，但依旧具备可以滚动的功能 */
	 display: none;
	 width: 0;
	 height: 0;
	 color: transparent;
	 background: transparent;
	}
	/deep/::-webkit-scrollbar {
	 display: none;
	 width: 0;
	 height: 0;
	 color: transparent;
	 background: transparent;
	}
</style>
